//
//  NSString+URLEncoding.m
//  WBusiness
//
//  Created by huangzhen on 2016/11/16.
//  Copyright © 2016年 huangzhen. All rights reserved.
//

#import "NSString+URLEncoding.h"

@implementation NSString (URLEncoding)

- (NSString *)stringByURLEncoding {
    /* CFURLCreateStringByAddingPercentEscapes iOS9弃用 */
    NSString *charactersToEscape = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\| ";
    NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet];
    NSString *encodedUrl = [self stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
    return encodedUrl;
}

- (NSString *)stringByURLDecoding
{
    /* CFURLCreateStringByReplacingPercentEscapesUsingEncoding iOS9弃用 */
    NSString *result = [self stringByRemovingPercentEncoding];
    return result;
}

@end
